<template>
	<view>
		<cu-custom><block slot="content">登陆</block></cu-custom>
		<view class="content" >
			<view class="logo_box">
				<view  style="text-align: center;line-height: 350upx;font-size: 100upx;">
					<image src="../../static/logo.png" style="width: 200upx;height: 200upx; margin-top: 110upx;"  ></image>
				</view>
			</view>
			<view class="input_box">
				<view class="m_input">
					<view class="input_text">
						账号：
					</view>
					<view class="input_value">
						<input maxlength=14 style="font-size: 30upx;" type="text" v-model="username" placeholder="请输入账号" @click="hideTabbar" @focus="hideTabbar" @blur="showTabbar" />
					</view>
				</view>
				<view class="m_input">
					<view class="input_text">
						密码：
					</view>
					<view class="input_value">
						<input  maxlength=14 type="text" :password="eye" v-model="password" placeholder="请输入密码" @click="hideTabbar" @focus="hideTabbar" @blur="showTabbar" />
					</view>
					<view class="eye" @click="eyeShow">
						<view  style="font-size: 45upx;line-height: 60upx;" class="iconfont" :class="[isActive ? activeClass : errorClass, activeClass]"></view>
					</view>
				</view>
			</view>
			<view class="bottom_box">
				<view class="aaaaa">
					<view class="login_bottom">
						<button size="default" type="primary" form-type="submit" @tap="bindLogin">登陆</button>
					</view>
					<view class="regist_bottom">
						<button size="default" type="default" form-type="submit" @tap="bindRegist">注册</button>
					</view>
				</view>
			</view>
			<view>
				<navigator url="../index/index" style="text-align: center;margin-top: 30upx;">
					<text>忘记密码</text>
				</navigator>
			</view>
			<view class="other_login_box">
				<view class="other_login_text">其他登陆方式</view>
				<view style="display: flex;">
					<view class="iconfont icon-qq other_login_icon_qq" ></view>
					<view class="iconfont icon-weixin other_login_icon_weixin" ></view>
					<view class="iconfont icon-weibo other_login_icon_weibo"></view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import "../../iconfont/iconfont.css"
	import {
		mapMutations,mapState
	}from 'vuex'
	export default {
		computed:{
			...mapState(['webUrl']),
		},
		data() {
			return {
				eye:true,
				isActive:false,
				activeClass: 'icon-yanjing',
				errorClass: 'icon-mimabukejian',
				username:"",
				password:"",
				tabber:true
			};
		},
		methods:{
			...mapMutations(['login']),
			//显示密码是否可见
			eyeShow() {
				this.eye = !this.eye;
				this.isActive = !this.isActive;
			},
			//登陆
			bindLogin(e){
				if(this.username.length < 5){
					uni.showToast({
					    icon: 'none',
					    title: '账号最短为 5 个字符'
					});
					return;
				}
				if(this.password.length < 6){
					uni.showToast({
					    icon: 'none',
					    title: '密码最短为 6 个字符'
					});
					return;
				}
				const user = this.username
				const pass = this.password
				uni.showLoading({
					title:"加载中"
				})
				uni.request({
					url: this.webUrl+"login",
					method:'POST',
					header:{
						'Content-Type': 'application/x-www-form-urlencoded',
					},
					data:{
						username : user,
						password : pass,
					},
					success:function(res) {
						if(res.data.status==1){
							uni.showToast({
								icon: 'none',
								title: '账号或密码错误'
							})
						}else if(res.data.status==0){
							this.login(res.data.data)
							uni.showToast({
								icon: 'none',
								title: '登陆成功'
							})
						}
					}.bind(this),
					fail:function(res){
						uni.showToast({
							icon: 'none',
							title: '登陆出错'
						})
						
					}
				})
			},
			//前往注册页面
			bindRegist(){
				uni.navigateTo({
					url:'../regist/regist'
				})
			},
			hideTabbar(){
				this.tabber = false
				this.$emit('func',this.tabber)
			},
			showTabbar(){
				this.tabber = true
				this.$emit('func',this.tabber)
			}
		},
	}
</script>

<style lang="stylus">
	.content {
		.logo_box {
			
			width: 100%;
			height: 350upx;
			//background-color: #0081FF;
		}
		.input_box {
			width: 100%;
			height: 200upx;
			background-color: #ffffff;
			.m_input {
				display: flex;
				height: 100upx;
				.input_text {
					text-align: center;
					line-height: 100upx;
					font-size: 35upx;
					width: 20%;
					
				}
				.input_value {
					margin-top: 22upx;
					margin-left: 0upx;
					width: 70%;
					
				}
				.eye {
					margin-top: 22upx;
					width: 10%;
				}
			}
		}
		.bottom_box {
			display:flex;
			width: 100%;
			height: 200upx;
			margin-top: 20upx;
			flex-direction: column;
				.login_bottom {
					margin-top: 10upx;
					padding-left:200upx;
					padding-right:200upx;
				}
				.regist_bottom {
					margin-top: 10upx;
					padding-left:200upx;
					padding-right:200upx;
				}
		}
		.other_login_box {
			.other_login_text {
				text-align: center;
				margin-top: 70upx;
			}
		
			.other_login_icon_qq {
				width: 33%;
				text-align: center;
				font-size:57upx;
				margin-top: 50upx;
			}
			.other_login_icon_weixin {
				width: 33%;
				text-align: center;
				font-size:70upx;
				margin-top: 50upx;
			}
			.other_login_icon_weibo {
				width: 33%;
				text-align: center;
				font-size:70upx;
				margin-top: 50upx;
			}
		}
	}
</style>
